package com.migu.rbac.model;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;


@Data
public class SysUser implements UserDetails {
    private Integer id;
    private String loginname;
    private String username;
    private String password;
    private String phone;
    private String projectid;

    public SysUser() {
    }

    public SysUser(String loginname, String username, String password, String phone) {
        this.loginname = loginname;
        this.username = username;
        this.password = password;
        this.phone = phone;
    }

    // @ManyToMany(cascade = {CascadeType.REFRESH},fetch = FetchType.EAGER)
    @JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY)
    private List<SysRole> roles;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
//        List<GrantedAuthority> auths = new ArrayList<>();
//        //List<SysRole> roles = this.getRoles();
//        for (SysRole role : roles) {
//            auths.add(new SimpleGrantedAuthority(role.getRolename()));
//        }
        return null;
    }


    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}